let mongoose = require('mongoose'),
    async = require('async'),
    resourcesPost = mongoose.model('resources_posts');

module.exports = (req, res) => {
    let params = req.body,
        me = this;

    if(!params.pid){
        res.json(resFail('PID不能为空！'))
        return false;
    }

    async.series([
        callback => {
            resourcesPost.find({
                pid: {
                    '$in': params.pid
                }
            }, (err, data) => {
                if(err){
                    res.json(resFail(err))
                }else{
                    if(!data.length){
                        res.json(resFail('查询结果为空'))
                    }else{
                        me.resourcesList = data;
                        callback();
                    }
                }
            })
        },
        callback => {
            resourcesPost.remove({
                pid: {
                    '$in': params.pid
                }
            }, err => {
                if(err){
                    res.json(resFail(err))
                }else{
                    res.json({
                        result: 1,
                        message: '删除成功'
                    })
                }
            })
        }
    ])
}
